package com.lzb.permanentcalendar.basic.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;

public class DataUtils {

    public static int getHour(String time){
        try {
            // 定义输入格式
            SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
            // 解析字符串为 Date 对象
            Date date = inputFormat.parse(time);

            if (date != null) {
                // 提取小时（24小时制）
                SimpleDateFormat hourFormat = new SimpleDateFormat("HH", Locale.getDefault());
                return Integer.parseInt(hourFormat.format(date));
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }


    public static String getTime(){
        // 获取当前日期
        Calendar calendar = Calendar.getInstance();

        // 格式化日期部分（年/月/日）
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
        String formattedDate = dateFormat.format(calendar.getTime());

        // 获取星期几并转换为中文
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
        String weekDay = weekDays[dayOfWeek - 1]; // Calendar中周日是1，周一是2

        // 合并结果（例如：2025/03/01 星期六）
        String result = formattedDate + "\n" + weekDay;
       return  result;
    }
    public static String getTime2(){
        // 获取当前日期
        Calendar calendar = Calendar.getInstance();

        // 格式化日期部分（年/月/日）
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String formattedDate = dateFormat.format(calendar.getTime());
        String result = formattedDate;
       return  result;
    }
    public static  List<String> getNext7DaysWithWeek() {
        List<String> strings = new ArrayList<>();
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd", Locale.CHINESE);

        for (int i = 0; i < 7; i++) {
            // 获取日期
            String dateStr = dateFormat.format(calendar.getTime());


            strings.add(dateStr);


            // 增加一天
            calendar.add(Calendar.DAY_OF_MONTH, 1);
        }

        return strings;
    }
    public static List<String>  getNext7DaysWithWeek1() {
        List<String> strings = new ArrayList<>();
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd", Locale.CHINESE);

        String[] weekDays = {"日", "一", "二", "三", "四", "五", "六"};

        for (int i = 0; i < 7; i++) {
            // 获取日期
            String dateStr = dateFormat.format(calendar.getTime());

            // 获取星期
            String weekInfo;
            if (i == 0) {
                weekInfo = "今日";
            } else if (i == 1) {
                weekInfo = "明日";
            } else {
                int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
                weekInfo = "周" + weekDays[dayOfWeek - 1];
            }

            strings.add(weekInfo);

            // 增加一天
            calendar.add(Calendar.DAY_OF_MONTH, 1);
        }

        return strings;
    }
}
